<template>
    <div class="main">
        <div class="searchDiv1">
            <!-- <x-input title="title"
                     v-model="name"
                     :show-clear="false"></x-input> -->
            <group>
                <popup-picker :data="equipmentType"
                              placeholder='默认全部'
                              v-model="equipmentTypeVal"></popup-picker>
            </group>
            <div class="search-wrap">
                <input type="text"
                       v-model="name"
                       placeholder="请输入关键字查询">
                <button @click="onClick"></button>
            </div>
        </div>
        <div class="basicMsg">
            <no-data v-if="acceptList.length==0 && flag"></no-data>
            <vue-better-scroll class="wrapper"
                               v-else
                               ref="scrollqq"
                               :scrollbar="scrollbarObj"
                               :pullDownRefresh="pullDownRefreshObj"
                               :pullUpLoad="pullUpLoadObj"
                               :startY="parseInt(startY)"
                               @pullingUp="onPullingUp">
                <dl ref="list"
                    @click="$router.push({path:'basicMessageDetail',query:{id:item.id}})"
                    v-for="(item,index) in acceptList"
                    :key="index">
                    <img class="useravatar"
                         :src="item.Faceurl"
                         alt=""/>
                    <dt>{{item.name}}<span>{{item.station === '管理人员'? '岗位':'工种'}}: {{item.Category}}</span>
                    </dt>
                    <dd>单位: {{item.departName}}</dd>
                </dl>
            </vue-better-scroll>
        </div>
        <div>
        </div>
        <myMenu></myMenu>
    </div>

</template>

<script>
import { XInput } from 'vux'
import VueBetterScroll from 'vue2-better-scroll'
import myMenu from '@/commonComponents/menu'
import { personList } from '@/api/api'
import noData from '@/commonComponents/noData/noData.vue'

export default {
    name: 'App',
    data () {
        return {
            name: '',
            flag: false,
            scrollbarObj: {
                fade: true
            },
            // 这个配置用于做下拉刷新功能，默认为 false。当设置为 true 或者是一个 Object 的时候，可以开启下拉刷新，可以配置顶部下拉的距离（threshold） 来决定刷新时机以及回弹停留的距离（stop）
            pullDownRefreshObj: false,
            // 这个配置用于做上拉加载功能，默认为 false。当设置为 true 或者是一个 Object 的时候，可以开启上拉加载，可以配置离底部距离阈值（threshold）来决定开始加载的时机
            pullUpLoadObj: {
                threshold: 0,
                txt: {
                    more: '加载更多',
                    noMore: '没有更多数据了'
                }
            },
            startY: 0, // 纵轴方向初始化位置
            scrollToX: 0,
            scrollToY: 0,
            scrollToTime: 700,
            acceptList: [], // 列表数据
            listCount: 0, // 当前页列表条数
            listAllCount: 0, // 列表总数
            userInfo: {},
            param: {
                allowPaging: true,
                data: {
                    DepartId: '393498467',
                    ReadCardID: '',
                    name: ''
                },
                pageIndex: 0,
                pageSize: 20
            },
            equipmentType: [['姓名', '单位']], //  搜索条件
            equipmentTypeVal: ['姓名'] // 选中的搜索条件
        }
    },
    components: {
        VueBetterScroll,
        XInput,
        noData,
        myMenu
    },
    created () {
        this.userInfo = JSON.parse(localStorage.userInfo)
        this.param.data.DepartId = this.userInfo.deptid
        // this.getData()
    },
    methods: {
        getData () {
            this.$vux.loading.show({
                text: '加载中...'
            })
            personList(this.param).then((res) => {
                if (res.code === 0) {
                    this.acceptList = res.data
                    this.listCount = this.acceptList.length
                    this.listAllCount = res.count
                }
            }).catch(() => {
                console.log('error')
            }).finally(() => {
                this.$vux.loading.hide()
                this.flag = true
            })
        },
        onPullingDown () {
            console.log('xl')
        },
        onPullingUp () {
            this.param.pageIndex++
            personList(this.param).then((res) => {
                if (res.code === 0) {
                    this.acceptList = this.acceptList.concat(res.data)
                    this.listCount = this.acceptList.length
                    this.listAllCount = res.count
                    if (this.listCount < this.listAllCount) {
                        this.$refs[`scrollqq`].forceUpdate(true)
                    } else {
                        this.$refs[`scrollqq`].forceUpdate(false)
                    }
                }
            }).catch(() => {
                console.log('error')
            }).finally(() => {
                this.$vux.loading.hide()
                this.flag = true
            })
        },
        onClick () {
            if (this.equipmentTypeVal[0] == '姓名') {
                this.param.data.name = this.name
                this.param.data.ReadCardID = ''
            } else {
                this.param.data.name = ''
                this.param.data.ReadCardID = this.name
            }

            this.param.pageIndex = 0
            this.getData()
        }
    }
}
</script>

<style lang="less" scoped>
@import '~vux/src/styles/1px.less';
@import '~vux/src/styles/center.less';

.basicMsg {
    position: fixed;
    top: 60px;
    width: 100%;
    height: 100%;
    left: 0;
    overflow: scroll;
    bottom: 100px;
    background: #fff;
    dl {
        height: 80px;
        border-bottom: 1px solid #f0f0f2;
        font-size: 12px;
        margin-left: 20px;
        overflow: hidden;
        background: url(../../../../static/images/index/more3.png) no-repeat
            right 20px center;
        background-size: 6px 10px;
        img {
            width: 50px;
            height: 50px;
            background: url('../../../assets/avatar2.png') no-repeat center
                center;
            background-size: 50px 50px;
            border-radius: 50%;
            margin: 15px 10px;
            float: left;
        }
        dt {
            width: 221px;
            line-height: 20px;
            overflow: hidden;
            text-overflow: ellipsis;
            white-space: nowrap;
            word-wrap: break-word;
            font-weight: bold;
            color: #343434;
            float: left;
            margin: 15px 0 13px 0;
            span {
                width: 100px;
                font-weight: 100;
                margin-left:10px;
                color: #6a6a6a;
            }
        }
        dd {
            width: 221px;
            float: left;
            color: #8d8d8d;
            overflow: hidden;
            white-space: nowrap;
            text-overflow: ellipsis;
        }
    }
}

.searchDiv1 {
    display: flex;
    align-items: center;
    height: 60px;
    background: #ebeef3;
    padding: 0 20px;
    overflow: hidden;
}
.search-wrap {
    display: flex;
    justify-content: center;
    height: 40px;
    margin: 10px auto;
    border-radius: 8px;
    background: #fff;
    padding: 10px 15px;
    flex: 1;
    margin-left: 10px;
    input {
        height: 20px;
        flex: 1;
        font-size: 14px;
        color: #666;
    }
    button {
        width: 24px;
        height: 25px;
        background: url(../../../../static/images/s_03.png) no-repeat center
            #fff;
        background-size: 24px 25px;
    }
}
</style>
<style>
.searchDiv1 .weui-cells {
    margin-top: 0;
    height: 40px;
    background: #fff;
    border-radius: 8px;
}
.searchDiv1 .vux-cell-value {
    font-size: 14px;
}
.searchDiv1 .weui-cell_access .weui-cell__ft::after {
    border-bottom-width: 2px;
    border-top-width: 0;
    top: -2px;
}
</style>
